﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using XRPGLibrary;
using XRPGLibrary.Controls;

namespace myRPG.GameScreens
{
    public class CharacterChoose : BaseGameState
    {
         #region Field Region
         LeftRightSelector genderSelector;//关于角色性别的selector控件
         //LeftRightSelector classSelector;//关于角色类型的selector控件
         PictureBox backgroundImage;//游戏背景图片框
        string[] genderItems = { "Prince", "Princess" };//用于初始化性别selector控件的字符串集
        //string[] classItems = { "Fighter", "Wizard", "Rogue", "Priest" };
         #endregion
         #region Property Region
         #endregion
         #region Constructor Region
        public CharacterChoose(Game game, GameStateManager stateManager)
         : base(game, stateManager)
         {
         }
         #endregion
         #region XNA Method Region
        public override void Initialize()
         {
        base.Initialize();
         }
        protected override void LoadContent()
         {
         base.LoadContent();
         CreateControls();
         }
        public override void Update(GameTime gameTime)
         {
         ControlManager.Update(gameTime, PlayerIndex.One);//对ControlManager进行更新，在其中会触发对页面上所有控件的更新
         base.Update(gameTime);
         }
        public override void Draw(GameTime gameTime)
         {
         GameRef.SpriteBatch.Begin();
         base.Draw(gameTime);
         ControlManager.Draw(GameRef.SpriteBatch);//ControlManager的绘制，在其中可以对页面上所有控件进行绘制
         GameRef.SpriteBatch.End();
         }
         #endregion
         #region Method Region
        private void CreateControls()
         {
        Texture2D leftTexture = Game.Content.Load<Texture2D>(@"img\ArrowLeft");
        Texture2D rightTexture = Game.Content.Load<Texture2D>(@"img\ArrowRight");
        Texture2D stopTexture = Game.Content.Load<Texture2D>(@"img\stop");
         backgroundImage = new PictureBox(
         Game.Content.Load<Texture2D>(@"Backgrounds\chooseBg"),
         GameRef.ScreenRectangle);
         ControlManager.Add(backgroundImage);//实例化背景控件，并加入到控件管理类中
         Label label1 = new Label();
         label1.Text = "Please Choose your Character";
         label1.Size = label1.SpriteFont.MeasureString(label1.Text);
         label1.Color = Color.Blue;
         label1.Position = new Vector2((GameRef.Window.ClientBounds.Width - label1.Size.X) /
        2, 150);
         ControlManager.Add(label1);//实例化标题label，并加入到控件管理类中
         genderSelector = new LeftRightSelector(leftTexture, rightTexture, stopTexture);
         genderSelector.SetItems(genderItems, 125);
         genderSelector.Position = new Vector2(label1.Position.X, 200);
         ControlManager.Add(genderSelector);//实例化性别selector，加入管理类
         /*classSelector = new LeftRightSelector(leftTexture, rightTexture, stopTexture);
         classSelector.SetItems(classItems, 125);
         classSelector.Position = new Vector2(label1.Position.X, 250);
         ControlManager.Add(classSelector);//实例化类型selector，加入管理类
          */
        LinkLabel linkLabel1 = new LinkLabel();
         linkLabel1.Text = "Accept this character.";
         linkLabel1.Position = new Vector2(label1.Position.X, 300);
         linkLabel1.Selected += new EventHandler(linkLabel1_Selected);
         linkLabel1.Color = Color.Blue;
         ControlManager.Add(linkLabel1);//实例化接受LinkLabel对象，加入管理类
         ControlManager.NextControl();//执行NextControl，使得当前呈现选项为被选中状态
         }
        void linkLabel1_Selected(object sender, EventArgs e)
         {
         InputHandler.Flush();
         StateManager.PopState();
         StateManager.PushState(GameRef.GamePlayScreen);//呈现游戏页面
         }
         #endregion
        }
}